programming4us
           
 
 
SQL Server

SQL Server 2008 : Indexing for Performance - Putting It All Together (part 2) - Clustered Index Seeks

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/30/2010 3:31:54 PM

3. Clustered Index Seeks

The first two index creations in Listing 1 create clustered indexes on the SalesOrderHeader and Product tables. Then comes a query. Then the listing creates a clustered index on the SalesOrderDetail table. Finally, the query is executed again, showing the improvement from using a clustered index over the table scan.

Example 1. SQL Script to Create Clustered Indexes and Retrieve Data from the Newly Created Tables
CREATE CLUSTERED INDEX ix_SalesOrderId ON
apWriter.SalesOrderHeader(SalesOrderId)

CREATE CLUSTERED INDEX ix_ProductId ON apWriter.Product(ProductId)

SELECT *
FROM apWriter.SalesOrderDetail
WHERE SalesOrderId = 74853

CREATE CLUSTERED INDEX ix_SalesOrderIdDetailId
ON apWriter.SalesOrderDetail(SalesOrderId,SalesOrderDetailId)

SELECT *
FROM apWriter.SalesOrderDetail
WHERE SalesOrderId = 74853

Figure 1 shows the execution plans from executing Listing 1. Notice the missing index message. You are notified of missing indexes by default in SQL Server 2008. The information in that message is the same that you could get manually by querying the missing index views described earlier.

Figure 3. The execution plan of a table scan versus a clustered index seek

Also notice the cost difference between the table scan and the clustered index seek. If you run your multiple table query for a sales order, you will see that clustered index seeks are used instead of table scans. For example, execute the following query. You should see an execution plan like that shown in Figure 2.

SELECT soh.SalesOrderId, soh.OrderDate, soh.ShipDate,p.Name, sod.OrderQty,
sod.UnitPrice, sod.LineTotal
FROM apWriter.SalesOrderHeader soh
JOIN apWriter.SalesOrderDetail sod ON soh.SalesOrderId = sod.salesOrderId
JOIN apWriter.Product p ON sod.ProductId = p.ProductId
WHERE soh.SalesOrderId = 74853

Figure 4. The execution plan of joining multiple tables using clustered index seeks
Other -----------------
- SQL Server Integration Services : Logged and Nonlogged Operations
- SQL Server Integration Services : Using bcp (part 5)
- SQL Server Integration Services : Using bcp (part 4)
- SQL Server Integration Services : Using bcp (part 3)
- SQL Server Integration Services : Using bcp (part 2) - Fundamentals of Exporting and Importing Data
- SQL Server Integration Services : Using bcp (part 1)
- SQL Server Integration Services : Connection Projects in Visual Studio
- SQL Server Integration Services : The Package Execution Utility (part 3) - The dtutil Utility
- SQL Server Integration Services : The Package Execution Utility (part 2) - Running Packages
- SQL Server Integration Services : The Package Execution Utility (part 1)
- SQL Server Integration Services : The SSIS Designer
- SQL Server Integration Services : Running the SSIS Wizard
- SQL Server Integration Services : A Data Transformation Requirement
- SQL Server 2008 : SSIS Tools and Utilities
- SQL Server 2008 : SSIS Architecture and Concepts
- SQL Server 2008 : SQL Server Integration Services - SSIS Basics
- Defensive Error Handling : Using Transactions and XACT_ABORT to Handle Errors
- Managing Security Within the Database Engine : Securables
- Managing Security Within the Database Engine : Database Security
- Managing Security Within the Database Engine : Creating SQL Server Principals
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us